package com.cms.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cms.entity.Model;
import com.cms.enums.ModelStatus;
import com.cms.mapper.ModelMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 内容模型表 服务实现类
 * </p>
 *
 * @author songfayuan
 * @since 2021-11-12
 */
@Service
public class ModelService extends ServiceImpl<ModelMapper, Model> {

    /**
     * 查找模型分页
     *
     * @param pageNumber
     *            页码
     * @param pageSize
     *            每页记录数
     * @return 模型分页
     */
    public Page<Model> findPage(Integer pageNumber, Integer pageSize){
        QueryWrapper<Model> queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("createDate");
        return baseMapper.selectPage(new Page<>(pageNumber, pageSize),queryWrapper);
    }

    /**
     * 查找启用模型列表
     *
     * @return 启用模型列表
     */
    public List<Model> findNormalList(){
        QueryWrapper<Model> queryWrapper = new QueryWrapper();
        queryWrapper.eq("status", ModelStatus.NORMAL.ordinal());
        queryWrapper.orderByDesc("createDate");
        return baseMapper.selectList(queryWrapper);
    }
}
